package xio.leetcode.java;


import xio.leetcode.java.base.ListNode;

/**
 * leetcode #206 反转链表
 *
 * 反转一个单链表。
 *
 * 示例:
 *
 * 输入: 1->2->3->4->5->NULL
 * 输出: 5->4->3->2->1->NULL
 *
 *
 */
public class LC206_ReverseLinkedList {
    public ListNode reverseList(ListNode head){
        ListNode root = new ListNode(Integer.MIN_VALUE);
        root.next = null;
        ListNode next;
        while (head != null){
            next = head.next;
            head.next = root.next;

            root.next = head;
            head = next;
        }
        return root.next;
    }
}
